package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.pojo.Emp;
import com.example.pojo.PageData;
import com.example.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service

public class EmpServiceImpl implements EmpService {
    @Autowired
    public EmpMapper empMapper;
    @Override
    public PageData page(String name, Integer gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);

        List<Emp> list = empMapper.page(name,gender,begin,end);

        Page<Emp> p = (Page<Emp>) list;
        return new PageData(p.getTotal(),p.getResult());
    }

    @Override
    public void delect(List<Integer> ids) {
        empMapper.delect(ids);
    }

    @Override
    public void insert(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        emp.setCreateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp select(Integer id) {
       Emp emp =  empMapper.select(id);
        return emp;
    }

    @Override
    public void updata(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updata(emp);
    }

    @Override
    public Emp login(Emp emp) {
       Emp e =  empMapper.getEmpbyUsernameandPassword(emp);
        return e;
    }
}
